Perl, `push` to array reference

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-06-16T15:37:51Z Indexed on 2010/06/16 15:42 UTC
Read the original article Hit count: 147

Filed under:
|
|

Is it possible to push to an array reference in Perl? Googling has suggested I deference the array first, but this doesn't really work. It pushes to the deferenced array, not the referenced array.

For example,

my @a = ();

my $a_ref = [@a];

push(@$a_ref,"hello");

print $a[0];

@a will not be updated and this code will fail because the array is still empty

(I'm still learning Perl references, so this might be an incredibly simple question. Sorry if so)

© Stack Overflow or respective owner

Related posts about perl

Related posts about array